#include<iostream>
using namespace std;



class binaryTreeNode
{
	public:
	int element;
	binaryTreeNode* leftChild;
	binaryTreeNode* rightChild;
	binaryTreeNode() { leftChild=rightChild = NULL; }  
	binaryTreeNode(int theElement) { element = theElement; leftChild=rightChild=NULL;}
	binaryTreeNode(int theElement,binaryTreeNode*theleftChild,binaryTreeNode*therightChild)  { element = theElement; leftChild=theleftChild;rightChild=therightChild; }
};


binaryTreeNode* RestoreTree(int preb,int pree,int inb, int ine,char preOrder[],char inOrder[])
{
	if(preb>pree||preb<0||inb>ine)
	   return NULL;
	binaryTreeNode* root=new binaryTreeNode(preOrder[preb]-48,NULL,NULL);
	int k=0;
	for(int i=inb;i<ine+1;i++)
	{
		if(preOrder[preb] == inOrder[i])
		{
			k=i;
			break;
		}
	}
	root->leftChild  = RestoreTree(preb+1,preb+k-inb,inb,k-1,preOrder,inOrder);
	root->rightChild = RestoreTree(preb+k-inb+1,pree,k+1,ine,preOrder,inOrder);

	 
	return root;
}  

void deleteTree(binaryTreeNode *t)
{
	if(t!=NULL)
	{
		deleteTree(t->leftChild);
		deleteTree(t->rightChild);
		delete t;
	}
}

void postOrder(binaryTreeNode* t)
{
	if(t==NULL) return;
	postOrder(t->leftChild);
	postOrder(t->rightChild);
	cout<<t->element<<" ";
}











int main()
{
	int n;
	cin>>n;
	char a[100];
	char b[100];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	binaryTreeNode* t=NULL;
	t=RestoreTree(0,n-1,0,n-1,a,b);
	postOrder(t);
	deleteTree(t);
}
